package com.lvbaoins.creditapp.core.reqres;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(value = "返回实体")
public class ResponseData<T> implements Serializable {

    public static final String DEFAULT_SUCCESS_MESSAGE = "成功";

    public static final String DEFAULT_ERROR_MESSAGE = "失败";

    public static final Integer DEFAULT_SUCCESS_CODE = 10000;

    public static final Integer DEFAULT_ERROR_CODE = 10001;

    /**
     * 请求是否成功
     */
    @ApiModelProperty(value = "true",name = "是否成功状态", example = "true")
    private Boolean success;

    /**
     * 响应状态码
     */
    @ApiModelProperty(value = "10000",name = "成功状态码", example = "10000")
    private Integer code;

    /**
     * 响应信息
     */
    @ApiModelProperty(value = "成功",name = "消息", example = "成功")
    private String message;

    /**
     * 响应对象
     */
    @ApiModelProperty(value = "具体返回信息", name = "返回内容")
    private T data;

    public ResponseData() {

    }

    public ResponseData(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static SuccessResponseData success() {
        return new SuccessResponseData();
    }

    public static SuccessResponseData success(Object object) {
        return new SuccessResponseData(object);
    }

    public static SuccessResponseData success(Integer code, String message, Object object) {
        return new SuccessResponseData(code, message, object);
    }

    public static ErrorResponseData error(String message) {
        return new ErrorResponseData(message);
    }

    public static ErrorResponseData error(Integer code, String message) {
        return new ErrorResponseData(code, message);
    }

    public static ErrorResponseData error(Integer code, String message, Object object) {
        return new ErrorResponseData(code, message, object);
    }
}
